﻿using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GzipManagerPro.IO.Helpers;

namespace GzipManagerPro.IO
{
    
    partial class Archive
    {
        [NonSerialized]
        private List<ArchiveErrorHandler> ErrorHandlers;

        [NonSerialized]
        private List<ArchiveMessageHandler> MessageHandlers;


        public event ArchiveErrorHandler ArchiveError
        {
            add
            {
                if (ErrorHandlers == null)
                    ErrorHandlers = new List<ArchiveErrorHandler>();

                ErrorHandlers.Add(value);
            }
            remove
            {
                ErrorHandlers.Remove(value);
            }
        }

        public event ArchiveMessageHandler ArchiveMessage
        {
            add
            {
                if (MessageHandlers == null)
                    MessageHandlers = new List<ArchiveMessageHandler>();

                MessageHandlers.Add(value);
            }
            remove
            {
                MessageHandlers.Remove(value);
            }
        }

        protected virtual void OnArchiveError(ArchiveErrorEventArgs e)
        {
            if (ErrorHandlers == null || ErrorHandlers.Count == 0)
                return;

            ErrorHandlers.ForEach(h => h(this, e));
        }

        internal protected virtual void OnArchiveMessage(ArchiveMessageEventArgs e)
        {
            if (MessageHandlers == null || MessageHandlers.Count == 0)
                return;

            MessageHandlers.ForEach(f => f(this, e));
        }
   }
}
